package com.lmx.persistence.service;

import java.util.List;
import java.util.Properties;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.lmx.common.util.PropertiesFileUtil;
import com.lmx.repoDomain.tmodel.Camera;

/**
 * 摄像头数据处理
 * 
 * @author 梁慕学
 * @version 1.00
 */
@Service
@Scope("prototype")
public class CameraService {
	private Log logger = LogFactory.getLog(this.getClass());

	private Properties properties = PropertiesFileUtil.getApplicationProperties();

	@PersistenceContext
	private EntityManager em;

	@Autowired
	protected GenericService dslJpaService;

	@Autowired
	protected CommonService commonService;

	
	/**
	 * 取得数据库中的摄像头列表
	 */
	public List<Camera> getCameraList() {
	    String query = "select c from Camera c";
        return this.em.createQuery(query).getResultList();
	}
    /**
     * 取得数据库中的摄像头列表
     */
    public Camera findByCode(String code) {
        String query = "select c from Camera c where c.code= ?1";
        List<Camera> l = this.em.createQuery(query).setParameter(1, code).getResultList();
        if(l.size()==0){
            return null;
        }
        return l.get(0);
    }
}
